package com.multimedia.scala

import scala.annotation.tailrec

object TailRecTest {
  @tailrec
  def factorial(number: Int, acc: BigInt = 1): BigInt = {
    //println(number+":"+acc)
    if (number<1) {
      return acc
    } else {
      return factorial(number-1, acc*number)
    }
  }
  @tailrec
  def factorialInt(number: Int, acc: Int = 1): Int = {
    //println(number+":"+acc)
    if (number<1) {
      return acc
    } else {
      return factorialInt(number-1, acc*number)
    }
  }
  @tailrec
  def factorialBig(number: BigInt, acc: BigInt = 1): BigInt = {
    //println(number+":"+acc)
    if (number<1) {
      return acc
    } else {
      return factorialBig(number-1, acc*number)
    }
  }

  def fibanacci(a: BigInt = 1, b: BigInt = 1): Stream[BigInt] = Stream.cons(a, fibanacci(b, a + b))
  
}